<?php
/**
 * @author Anh Nguyen
 * @copyright 2012
 */
 defined('APP') or die('Denied access !');
 
class Controller
 {
    protected $load;
    protected $tpl;
    protected $cache;
    protected $layout;
    
    function __construct()
    {
        $this->load = new Loader();
        $this->tpl = $this->load->library('Template');
        $this->cache = $this->load->library('Cache');
        $this->layout = $this->load->library('Layout');
        $this->tpl->tpl_dir = MODULE_PATH . DS . Router::$module . DS . 'views';
        $this->tpl->tpl_ext = Core::$config['template_ext'];
        
        if($this->cache->get('url_index') == NULL) {
            $this->cache->set('url_index', array(
                                'url_home'      =>      Core::site_url('home'),
                                'url_idea'      =>      Core::site_url('idea'),
                                'url_news'      =>      Core::site_url('news'),
                                'url_contact'   =>      Core::site_url('contact'),
                                'url_about'     =>      Core::site_url('about')
                                    ));   
        }
    }
    
    protected function load_header()
    {
        if( !isset($_SESSION[Core::$config['session_pre'] . 'username']) OR !isset($_COOKIE[Core::$config['session_pre'] . 'username'])) {
            for($i=1; $i<=31; $i++)
            {
                $this->tpl->assign('day',$i);
                $this->tpl->parse('uBirthday-Day');
                
                if($i <= 12) {
                    $this->tpl->assign('month',$i);
                    $this->tpl->parse('uBirthday-Month');
                }
            }
            for($i=1900; $i <= gmdate('Y',time()); $i++)
            {
                $this->tpl->assign('year', $i);
                $this->tpl->parse('uBirthday-Year');
            }
            $this->tpl->assign('url_captcha',Core::site_url('captcha'));
            $this->tpl->parse('login_form');
        }
        $this->tpl->parse('login');
    }
    
    public function load_footer()
    {
        $combine_js = $this->layout->GetCombined('js');
        $combine_css = $this->layout->GetCombined('css');
        $this->tpl->assign( array(
                                    'combine_js'    => $combine_js,
                                    'combine_css'   =>  $combine_css
                                    ));
        $this->tpl->parse('Css_Js');
        $this->tpl->parse('footer');
    }
 }
?>